<template>
  <el-dropdown @command="handleCommand">
    <span class="el-dropdown-link">
      <el-avatar shape="square" src="https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png" />
      <el-icon class="el-icon--right"><ArrowDown /></el-icon>
    </span>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item command="center">修改密码</el-dropdown-item>
        <el-dropdown-item v-if="false" command="set">设置</el-dropdown-item>
        <el-dropdown-item command="logout" divided>退出</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
  <DialogPersonalCenter ref="dialogPersonalCenterRef" />
</template>
<script setup lang="ts">
import DialogPersonalCenter from '@/dialog/PersonalCenter/Index.vue'
import { ArrowDown } from '@element-plus/icons-vue'
import { ref } from 'vue'

const dialogPersonalCenterRef = ref()

const handleCommand = (command: string) => {
  console.log(command)
  switch (command) {
    case 'center':
      if (dialogPersonalCenterRef.value) {
        dialogPersonalCenterRef.value.openDialog()
      }
      break
    case 'set':
      window.location.replace('/set')
      break
    case 'logout':
      window.location.href = '/login?' + Date.now()
      break
  }
}
</script>
<style lang="scss" scoped>
.el-dropdown-link {
  display: flex;
  justify-self: center;
  align-items: center;
}
</style>
